/*************************************************************************
	> File Name: P1626.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-10 17:46:59
 ************************************************************************/
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 100000
int arr[MAX_N + 5], num[MAX_N + 5];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    for (int i = 1; i < n; i++) {
        num[i] = arr[i] - arr[i - 1];
    }
    sort(num + 1, num + n);
    int sum = 0;
    for (int i = 1; i <= k; i++) {
        sum += num[i];
    }
    cout << sum << endl;
    return 0;
}
